﻿namespace ScrumLite.Services.Contracts
{
    using System;
    using System.Runtime.Serialization;
    using System.Globalization;

    [DataContract]
    public class RequestPage
    {
        [DataMember]
        public int NoPage { get; set; }

        [DataMember]
        public int NoPages { get; set; }

        [DataMember]
        public Request[] Requests { get; set; }
    }

    [DataContract]
    public class Request
    {
        [DataMember]
        public Guid Id { get; set; }

        [DataMember]
        public int Moniker { get; set; }

        [DataMember]
        public string Title { get; set; }

        [DataMember]
        public string Notes { get; set; }

        [DataMember]
        public int? Priority { get; set; }

        [DataMember]
        public int? Weight { get; set; }

        [DataMember]
        public int? Order { get; set; }

        [DataMember]
        public bool Committed { get; set; }

        [DataMember]
        public RequestStatus Status { get; set; }

        [DataMember]
        public string Requestor { get; set; }

        [DataMember]
        public DateTime CreatedOn { get; set; }

        [DataMember]
        public DateTime? CompletedOn { get; set; }

        [DataMember]
        public DateTime? DueOn { get; set; }

        [DataMember]
        public string DaysToDue
        {
            get {
                if (DueOn == null)
                    return String.Empty;

                return TimeSpanToDue.Value.Days.ToString(CultureInfo.InvariantCulture);
            }
            private set
            {
            }
        }

        public TimeSpan? TimeSpanToDue
        {
            get
            {
                if (DueOn == null)
                    return null;

                if (!CompletedOn.HasValue)
                    return DueOn.Value.Subtract(DateTime.Today);
                else
                    return TimeSpan.Zero;
            }
        }

        [DataMember]
        public WorkArea[] WorkAreas { get; set; }
    }

    public enum RequestStatus : int
    {
        Taken = 1,
        Waiting = 2,
        Blocked = 3, 
        Completed = 4,
        Postponed = 5
    }
}
